#ifndef MCL_RT_H_
#define MCL_RT_H_

#include "mcl/val.h"

struct vbind {
	struct dstr name;
	struct lvalue *val;
};

DEFINE_DA(da_valptr, struct lvalue *);
DEFINE_DA(da_vbind, struct vbind);

struct env {
	struct da_vbind binds;
	struct env *parent;
};

struct runtime {
	struct da_valptr living[2];
	usize currl;

	struct env rootenv;
	struct da_pos func_stack;

	bool panic;
};

#define RUNTIME_INIT \
	{ \
		.living[0] = DA_INIT, \
		.living[1] = DA_INIT, \
		.currl = 0, \
		.rootenv = {.binds = DA_INIT, .parent = NULL}, \
		.panic = false, \
	};

void env_bind(struct env *env, struct dstr name, struct lvalue *val);
struct lvalue *env_find(struct env *env, struct dstr *name);
struct lvalue *eval(struct runtime *rt, struct env *env, struct lvalue *v);

#endif
